/*******************************************************************************
GSprite.h

	Author:		LiuDingXi
	e-mail:		liudx@gmail.com
	Date time:	2009-08-07

	Copyright (C) 2009
	All rights reserved.
	
*******************************************************************************/

#ifndef _GSPRITE_H_
#define _GSPRITE_H_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include "GEngine.h"
#include "GScene.h"

enum POS_FLAG {
	PF_TOPLEFT,
	PF_TOPMIDDLE,
	PF_TOPRIGHT,
	PF_LEFTMIDDLE,
	PF_RIGHTMIDDLE,
	PF_MIDDLE,
	PF_BOTTOMLEFT,
	PF_BOTTOMRIGHT,
	PF_BOTTOMMIDDLE,
};

class GSprite : public GObject
{
public:
	GSprite();
	virtual ~GSprite();


	BOOL DataBind(GSight* pSight,  const BYTE* pBase, SceneDat::PTR ptr);

	void OnDraw(GDC* pDC, int x, int y, int frame);

	void OnDraw(GDC* pDC);
	bool IsVisible()const;

	void SetPosEx(int x, int y, int nFlag);

	BOOL GetPos(POS& refPos)const;
	BOOL GetBox(BOX& refBox)const;
	BOOL GetCxy(CXY& refCxy)const;

	SINT HitTest(int x, int y);

	void Update(UINT nMillisecond);

public:
	SINT GetAction();
	SINT SetAction(SINT nAction);

	void OnDrawFrame(GDC* pDC, SINT nAction, SINT nFrame, int x, int y);
	CXY DrawClip(GDC* pDC, int x, int y, SINT nClip);

	void SetActFrame(int nIndex);
	SINT GetActFrame()const;
	
	void ResetDelay();
	BOOL IsPlayEnded()const;
	void ResetAction();

protected:
	GSight*			m_pSight;

	const BYTE*		m_pBase;
	const SPRITE*	m_pThis;

	int				m_nAction;
	int				m_nFrame;
	int				m_nDelay;

	unsigned long	m_nUpdated;
};


#endif//_GSPRITE_H_
